<template>
	<view class="main-body flex flex-col">
		<u-sticky>
			<u-tabs :list="tabList" :is-scroll="false" :current="current" @change="tabChange"></u-tabs>
			<div class="up-btn-box">
				<u-button @click="toAdd" type="primary">上报隐患</u-button>
			</div>
		</u-sticky>
		
		<div class="event-list flex-auto overflow-auto">
			<div v-for="(item,index) in list" class="event-list-item" @click="handle(item.danger_id)">
				<div class="img-box">
					<u-image width="100%" height="300rpx"
						:src="item.up_resource.length>0?item.up_resource[0].res_url:''">
					</u-image>
				</div>
				<div class="conent-box">
					<div class="title">{{item.position}}</div>
					<div class="dis">{{item.flow_msg}}</div>
					<div class="btn-box">
						<u-button type="primary" size="mini" v-if="item.can_do == 1 && tabStatus === 1" @click="handle(item.danger_id,'assign')">指派</u-button>
						<u-button type="primary" size="mini" v-if="item.can_do == 1 && tabStatus === 2" @click="handle(item.danger_id,'handle')">处理</u-button>
						<u-button type="primary" size="mini" v-if="tabStatus === 3" @click="handle(item.danger_id,'check')">验收</u-button>
						<u-button type="primary" size="mini" v-if="tabStatus === 4">查看</u-button>
						<u-button type="error" size="mini" v-if="tabStatus === 1" @click="del(item.danger_id)">删除</u-button>
					</div>
				</div>
				
			</div>
			<u-loadmore :status="status" />
		</div>
		<!-- <view class="item u-border-bottom" v-for="(item, index) in list2" :key="index">
			{{'第' + item + '条数据'}}
		</view> -->
		<u-modal v-model="layerShow" @confirm="layerConfirm" :show-cancel-button="true" :content="layerContent"></u-modal>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {list,deleteDanger} from "@/api/hidden";
	export default {
		data() {
			return {
				tabList: [{
					name: '上报'
				}, {
					name: '待处理'
				}, {
					name: '待验收'
				}, {
					name: '已验收'
				}],
				current: 0,
				list: [],
				tabStatus: 1,
				list2: 30,
				page:1,
				status: 'loadmore',
				layerContent:'',
				layerShow:false,
				delId:0
			}
		},
		onReachBottom() {
			console.log(111)
			if (this.page >= 3) return;
			this.status = 'loading';
			this.page = ++this.page;
			setTimeout(() => {
				if (this.page >= 3) this.status = 'nomore';
				else this.status = 'loading';
				this.getHiddenList()
			}, 200)
		},
		onLoad() {
			this.getHiddenList()
		},
		methods: {
			toAdd() {
				uni.navigateTo({
					url: 'form?type=edit'
				});
			},
			tabChange(index) {
				this.current = index;
				this.tabStatus=index+1
				this.page=1
				this.list=[]
				this.getHiddenList()
			},
			getHiddenList() {
				list({
					user_id: uni.getStorageSync('userInfo').id,
					org_id: uni.getStorageSync('userInfo').org_id,
					status: this.tabStatus,
					page: this.page
				}).then(res => {
					this.list=this.list.concat(res.data.data.data);
				})
			},
			toView(id){
				console.log(123)
				uni.navigateTo({
					url: '/pages/hidden/form?id=' + id
				})
			},
			handle(id,act="view"){
				uni.navigateTo({
					url: '/pages/hidden/handle?id='+id+'&act='+act
				});
			},
			del(id){
				console.log(1,id)
				this.layerContent = '是否删除？'
				this.layerShow = true
				this.delId = id
			},
			layerConfirm(){
				console.log(222,this.delId)
				deleteDanger({
					user_id: uni.getStorageSync('userInfo').id,
					org_id: uni.getStorageSync('userInfo').org_id,
					danger_id:this.delId,
				}).then(res => {
					this.$refs.uToast.show({
						title: '删除成功',
						type: 'success',
						url: '/pages/hidden/hidden'
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "./hidden.scss";
</style>
